home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 1156 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.1 KB

  1. Path: fido.asd.sgi.com!austern
  2. From: Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Is RTTI required if polymorphic constructor exists
  5. Date: 18 Apr 1996 09:42:40 PDT
  6. Organization: Technical University of Berlin
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <31761AD4.6173@cs.tu-berlin.de>
  9. References: <4kng7f$kt9@nuscc.nus.sg> <4kr21b$6ar@mulga.cs.mu.OZ.AU> <4l30l2$31v@nuscc.nus.sg> <31755193.113D@cyberspy.com>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: Thu, 18 Apr 1996 12:35:00 +0200
  12. X-Mailer: Mozilla 2.0 (Win95; I)
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMXZxAUy4NqrwXLNJAQEmFwH+Og3xwAXoI2+0KorWQ1YVvgV1YqvjIKin
  15.     86YCm6rezKfXZ/xO9LSpesqD0n+M8eKb+68IeQ3AJ7aZZsblY9EMBw==
  16.     =4FJN
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. Rich Paul wrote:
  20. > Satrajit Sujit Ghosh wrote:
  21. > >
  22. > >         Would it be possible to illustrate efficient, convenient and
  23. > > pratical use of the RTTI functions?
  24. > >
  25. > Hmmm ... well, this comes in handy:
  26. > ostream &operator << ( ostream &os, const exception &e )
  27. > {
  28. >         return os << endl
  29. >                   << "Exception: " << typeid(e).name() << endl
  30. >                   << "Message:   " << e.what() << endl;
  31. > };
  32. > Since the typename of the exception carries some of the most relevent
  33. > information about the exception, why not use it ... of course, the
  34. > same thing could be done with virtual functions.
  35.  
  36. Except that typeid(e).name() returns an implementation-defined value which ( 
  37. if my reading of the April DWP is correct ) is not necessarily a 
  38. null-terminated string. It might even be an invalid pointer so that the above 
  39. function wouldn't work at all. I don't know if this has already been done but 
  40. if not - why not guarantee that the pointer is at least valid?
  41.  
  42. Bye
  43.  
  44. Roman
  45. ---
  46. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  47.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  48.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  49.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  50.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  51. ]
  52.